﻿using Microsoft.Extensions.DependencyInjection;
using Quick.EntityFrameworkCore.Options;

namespace Quick.EntityFrameworkCore;

public class AutoConfigureDbContextOptionsBuilder
{
    public IServiceCollection Services { get; protected set; }

    public AutoConfigureDbContextOptionsBuilder(IServiceCollection services)
    {
        Services = services;
    }

    public AutoConfigureDbContextOptionsBuilder AddDatabaseSupport<T>()
        where T : IEntityFrameworkCoreDatabaseOptionsProvider, new()
    {
        var instance = new T();

        Services.AddKeyedSingleton(typeof(IEntityFrameworkCoreDatabaseOptionsProvider), instance.Name, instance);

        return this;
    }

    public AutoConfigureDbContextOptionsBuilder AddProviderNameAccessor<TAccessor>()
        where TAccessor : class, IProviderNameAccessor
    {
        Services.AddTransient<IProviderNameAccessor, TAccessor>();

        return this;
    }

    public AutoConfigureDbContextOptionsBuilder AddConnectionStringAccessor<TAccessor>()
        where TAccessor : class, IConnectionStringAccessor
    {
        Services.AddTransient<IConnectionStringAccessor, TAccessor>();

        return this;
    }
}
